<template>
    <div>
        <el-dialog title="详情" :visible.sync="preOpens" width="800px" append-to-body>
            <div>
                <div class="title"
                    style="width: 100%;text-align: center;font-size: 20px;font-weight: bold;line-height: 50px;">{{
                        priviewInner.articleTitle }}</div>
                <div class="" style="width: 100%;text-align: center;font-size: 14px;color: #999;line-height: 30px;">
                    作者：{{ priviewInner.authorName ? priviewInner.authorName : "无" }}</div>
                <div class="my_content" v-html="priviewInner.articleContent"
                    style="width: 100%;padding: 10px;padding-bottom: 50px;"></div>
            </div>
            <el-divider></el-divider>
            <div style="font-size: 20px;font-weight: bold;" v-if="isForm">
                <div style="padding-bottom: 20px;">审核意见</div>
                <el-form  ref="form" :model="form" :rules="rules" label-width="120px">
                    <el-form-item label="审核状态:" prop="examine_state">
                        <el-radio v-model="form.examine_state" label="1">审核通过</el-radio>
                        <el-radio v-model="form.examine_state" label="2">审核驳回</el-radio>
                    </el-form-item>
                    <el-form-item label="审核意见:" prop="examineFailedReason">
                        <el-input type="textarea" placeholder="请输入审核意见或改进措施" v-model="form.examineFailedReason"
                            maxlength="100" show-word-limit style="width: 500px;" rows="5">
                        </el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer" style="text-align: center;">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { ArticlePreview, contentReviewCopyright, contentReviewTwo } from '@/api/my'
export default {
    props: {
        preOpen: {
            type: Boolean,
            required: true,
            default: false,
        },
        myRow: {
            type: Object,
            required: true,
            default: {}
        },
        isForm: {
            type: Boolean,
            required: true,
            //default:false,
        },
        isTwo: {
            type: Boolean,
            required: false,
            default: false
        }

    },
    //props: ['preOpen','topicId','isForm'],  //开关状态和id要传,
    data() {
        return {
            form: {
                examine_state: null,  //审核状态
                examineFailedReason: ''   //审核意见
            },
            priviewInner: [],  //预览列表
            rules: {
                examine_state: [
                    { required: true, message: "请选一个审核状态", trigger: "blur" }
                ],
                examineFailedReason: [
                    { required: true, message: "必须填写审核意见", trigger: "blur" }
                ]
            }
        }
    },
    created() {

    },
    computed: {
        preOpens: {
            get() {
                // return  this.waitForResult()
                if (this.preOpen) {
                    this.preData()
                }
                return this.preOpen
            },
            set(newValue) {
                this.cancel()
            }
        }
    },
    methods: {
        async postData() {
            let data = {
                examineState: this.form.examine_state,
                examineFailedReason: this.form.examineFailedReason,
                contentId: this.myRow.articleId
            }
            // console.log(data);
            // return
            if (this.isTwo) {
                let res = await contentReviewTwo(data)
                if (res.code == 200) {
                    this.$notify.success({
                        title: '成功',
                        message: '提交审核成功'
                    })
                    this.cancel()
                    this.$emit('flushList')
                }
            } else {
                let res = await contentReviewCopyright(data)
                if (res.code == 200) {
                    this.$notify.success({
                        title: '成功',
                        message: '提交审核成功'
                    })
                    this.cancel()
                    this.$emit('flushList')
                }
            }
        },
        submitForm() {  //提交
           // console.log(888);
            this.$refs.form.validate((value) => {
                if (!value) return
                this.postData()
            })
        },
        cancel() {
            this.priviewInner = []
            this.form = {
                examine_state: null,  //审核状态
                examineFailedReason: ''   //审核意见
            },
                this.$emit('updatePre', false)
        },
        async preData() {
            let res = await ArticlePreview({ articleTopicId: this.myRow.topicId })
            this.priviewInner = res.data
           
            // return new Promise((resovle)=>{
            //     resovle()
            // })
            // this.preOpen = true
             console.log(this.priviewInner,'12111');
        },
    },

}
</script>

<style lang='scss' scoped>
</style>